package com.foreknow.demo26;

import java.io.*;

import java.util.List;

/**
 * 功能类
 * 读、写的方法
 */

public class ReadWrite {

    public void Write(List list){

        FileWriter fw = null;
        BufferedWriter bw = null;

        try {
            fw = new FileWriter("Student.txt");
            bw = new BufferedWriter(fw);
            for(int i=0; i<list.size();i++){
                Student stu = (Student)list.get (i);
                String line = stu.getId()+"  "+stu.getName()+"  "+stu.getSchool()+"   "+stu.getPnum();
                bw.write(line);
                bw.newLine();
            }
            System.out.println("存入成功。。。。");
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public void Read(){
        FileReader fr = null;
        BufferedReader br = null;
        try {
            fr = new FileReader("Student.txt");
            br = new BufferedReader(fr);
            String line = br.readLine();
            while(line!=null){
                System.out.println(line);
                line = br.readLine();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
